﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.Lib;
using Components;

namespace UI.ShopManagement
{
    public partial class FrmBas1a25Edit : UI.ParentForm.BaseEdit
    {
        public FrmBas1a25Edit(string action, string text, string key)
            : base(action)
        {
            InitializeComponent();

            this.Text = text;
            this.key = key;
            //回写的方法
            this.SaveCallFuntion = "Bas1a25Manager$SaveData"; //保存的方法
            if ("A" == this.Action)
            {
                IsAfterSaveCloseWin = false;
            }
            else
            {
                LoadData();
            }
            this.Size = base.MidWindow;
        }

        protected override bool Check()
        {
            if ("A" == this.Action)
            {
                //zhuqiangwei 2011-03-09修改成同一个销售商同一家门店下也不能重复
                System.Collections.Hashtable hs = new System.Collections.Hashtable();
                hs["addcode"] = this.tbSummary.GetValue("addcode");
                hs["%muser"] = UI.Lib.Context.GetAppKeyWhere();
                hs["slistid"] = this.tbSummary.GetValue("slistid");
                hs["plistid"] = this.tbSummary.GetValue("plistid");
                bool reflt = UI.Lib.Factory.CommonHelper.Entity.DataInData("Bas1a25", hs);
                if (reflt)
                {
                    MessageBox.Show("销售商 + 门店 + 地址代码已经存在！", "提示");
                    this.tbSummary.Focus("addcode");
                    return false;
                }

                return true;
            }

            return true;
        }

        public override bool BeforePopWin(string name, ref string where, ref string[] others)
        {
            //销售商
            if ("sellercode" == name)
            {
                where = string.Format(" status ='1' {0} ", Context.GetAppKeyWhere("usercode", true));
            }
            else if ("shopcode" == name)
            {
                string sellerid = Validation.ToString(this.tbSummary.GetValue("slistid"));
                if (string.IsNullOrEmpty(sellerid))
                {
                    MessageBox.Show("请先录入[销售商代码]信息!", "提示");
                    this.tbSummary.Focus("sellercode");
                    return false;
                }

                where = string.Format(" slistid = '{0}' {1} ", sellerid, Context.GetAppKeyWhere("muser", true));
            }

            return true;
        }

        public override void AfterPopWin(string name, System.Collections.Hashtable data, bool ischange)
        {
            //当销售商的弹出框的值改变时，清空门店框
            if ("sellercode" == name && ischange)
            {
                this.tbSummary.SetValue("shopcode", "");
                this.tbSummary.SetValue("shopname", "");
                this.tbSummary.SetValue("plistid", "");
            }
        }

        //加载修改数据
        private void LoadData()
        {
            base.LoadEditData(null, string.Format(" a.listid ='{0}' ", this.key));
        }
    }
}